package se.webbzon.boltzmann.battle.object.spawner;

import java.nio.ByteBuffer;

import se.webbzon.oschi01.worldeditor.WorldStaticObjectDeflation;

public class BattleSpawnerDeflation extends WorldStaticObjectDeflation {
	
	private int factionId, groupId, order;
	
	private boolean facingLeft;

	/*============================================================
	Constructors
	============================================================*/
	
	public BattleSpawnerDeflation(int deflationProperties) {
		super(deflationProperties,null);
	}
	
	public BattleSpawnerDeflation(int deflationProperties, BattleSpawner spawner) {
		super(deflationProperties,null,spawner);
		factionId = spawner.getFactionId();
		groupId = spawner.getGroupId();
		order = spawner.getOrder();
		facingLeft = spawner.isFacingLeft();
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Creates a new spawner from this deflation. **/
	public BattleSpawner makeSpawner() {
		BattleSpawner spawner = 
				new BattleSpawner(factionId,groupId,order,facingLeft);
		spawner.setPosition(getX(),getY(),getZ());
		spawner.setSize(getWidth(), getHeight(), getWidth());
		spawner.setRotation(getEX(), getEY(), getEZ(), getAngle());
		return spawner;
	}
	
	@Override public void inflate(ByteBuffer buff) {
		super.inflate(buff);
		factionId = buff.getInt();
		groupId = buff.getInt();
		order = buff.getInt();
		facingLeft = (buff.get() != 0);
	}

	@Override public ByteBuffer deflate(int allocate) {
		ByteBuffer buff = super.deflate(allocate + 13);
		buff.putInt(factionId);
		buff.putInt(groupId);
		buff.putInt(order);
		buff.put(facingLeft ? (byte) 1 : (byte) 0);
		return buff;
	}
	
}
